package com.ruoyi.business.enums;

import java.util.Arrays;
import java.util.Optional;

public enum TradeState {
    SUCCESS("SUCCESS","支付成功") ,
    REFUND("REFUND","转入退款") ,
    NOTPAY("NOTPAY","未支付") ,
    CLOSED("CLOSED","已关闭") ,
    REVOKED("REVOKED","已撤销（付款码支付）") ,
    USERPAYING("USERPAYING","用户支付中（付款码支付）") ,
    PAYERROR("PAYERROR","支付失败(其他原因，如银行返回失败)") ;
    private String code ;
    private String desc ;

    TradeState(String code, String desc){
        this.code = code ;
        this.desc = desc ;
    }

    public static boolean checkExist(String code){

        Optional<TradeState> dealOp = Arrays.stream(TradeState.values()).filter(deal -> deal.code == code).findFirst() ;
        return dealOp.isPresent() ;
    }

    public String getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public static String getDescByCode(String code){
        Optional<TradeState> dealOp = Arrays.stream(TradeState.values()).filter(deal -> deal.code.equals(code)).findFirst() ;
        return dealOp.get().desc ;
    }
}
